// pages/money/money.js
import { VirtualPay } from "../../utils/virtualPay.js"
var virtualPay = new VirtualPay();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentMoney:0,
    moneyRecords: [],
    currentPage:1,
    stopMore:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '余额记录'
    })

    virtualPay.getMoney(1, (res) => {
      if (virtualPay.processRes) {
        if (res.data.data.data) {
          this.setData({
            currentMoney: res.data.current_money,
            moneyRecords: res.data.data.data,
            currentPage: res.data.data.current_page
          })
        }
      }
    })
  },

    

  onReachBottom: function () {
    if(this.data.stopMore){
      virtualPay.toast("没有更多记录了","none")
      return
    }

    var page = this.data.currentPage + 1;
    virtualPay.getMoney(page, (res) => {
      if (virtualPay.processRes) {
        var result = virtualPay.updataList(res.data, this.data.moneyRecords)
        this.setData({
          stopMore: result.stopMore,
          moneyRecords: result.data,
          currentPage: result.currentPage,
          currentMoney: res.data.current_money
        })
      }
    })
  }
})